<?php
// +----------------------------------------------------------------------

namespace app\api\model;

use think\Model;
use think\facade\Db;

/**
 * 时间模型
 * @package app\api\model
 */
class Times extends Model
{
	/**
	 * 获取当前季度开始和结束时间
	 * @param $time 时间戳
	 * @return array 开始时间和结束时间
	 * @author 迅 
	 * @date 2020/04/20 17:10
	 */
	public static function Quarter($time = 0)
	{
		// 默认当前时间戳
	    if($time === 0) $time = time();
		$year	= date('Y', $time);
		$month	= date('m', $time);
		// 判断月份
		switch($month){
			case ($month <= 3):
			$array = [
				'begin'	=> strtotime($year.'0101'),
				'end'	=> strtotime($year.'0401') - 1,
			];
			break;
			case ($month <= 6):
			$array = [
				'begin'	=> strtotime($year.'0401'),
				'end'	=> strtotime($year.'0701') - 1,
			];
			break;
			case ($month <= 9):
			$array = [
				'begin'	=> strtotime($year.'0701'),
				'end'	=> strtotime($year.'1001') - 1,
			];
			break;
			case ($month <= 12):
			$array = [
				'begin'	=> strtotime($year.'1001'),
				'end'	=> strtotime($year.'1231') + 3600*24 -1,
			];
			break;
			default:
			$array = [];
		}
		return $array;
	}
	/**
	 * 获取当前月开始和结束时间
	 * @param $time 时间戳
	 * @return array 开始时间和结束时间
	 * @author 迅 
	 * @date 2020/04/20 17:10
	 */
	public static function Month($time = 0)
	{
		// 默认当前时间戳
	    if($time === 0) $time = time();
		$year	= date('Y', $time);
		$month	= date('m', $time);
		// 判断月份
		switch($month){
			case ($month < 12):
			$array = [
				'begin'	=> strtotime($year.$month.'01'),
				'end'	=> strtotime($year.$month + 1 .'01') - 1,
			];
			break;
			case ($month == 12):
			$array = [
				'begin'	=> strtotime($year.$month.'01'),
				'end'	=> strtotime($year.$month.'31') + 3600*24 -1,
			];
			break;
			default:
			$array = [];
		}
		return $array;
	}
	
	/**
	 * 获取当天开始和结束时间
	 * @param $time 时间戳
	 * @return array 开始时间和结束时间
	 * @author 迅 
	 * @date 2020/04/20 17:10
	 */
	public static function Day($time = 0)
	{
		// 默认当前时间戳
	    if($time === 0) $time = time();
		
		// 当日零点时间戳
		$today = strtotime(date('Ymd', $time));
		
		$array = [
			'begin'	=> $today,
			'end'	=> $today + 3600*24 -1,
		];
		return $array;
	}
}
